package cn.tom.service.impl;

import cn.tom.entity.Certificate;
import cn.tom.mapper.CertificateMapper;
import cn.tom.service.CertificateService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@CacheConfig //缓存配置
public class CertificateServiceImpl extends ServiceImpl<CertificateMapper, Certificate> implements CertificateService {

    @Autowired
    CertificateMapper certificateMapper;

    /**
     * Logger输出
     */
    private Logger log
            = LoggerFactory.getLogger(cn.tom.tool.Log.class);

    /**
     * 查询最新的5条证书
     */
    @Override
    public List<Certificate> findByDay() {
        List<Certificate> byDay = certificateMapper.findByDay();
        return byDay;
    }

    /**
     * 全查询
     *
     * @return
     */
    @Override
    public List<Certificate> findAll() {
        List<Certificate> certificates = certificateMapper.selectList(null);
        return certificates;
    }

    /**
     * 根据证书ID查询
     */
    @Override
    public Certificate findById(Integer id) {
        Certificate certificate = certificateMapper.selectById(id);
        return certificate;
    }

    /**
     * 添加一个证书
     *
     * @param certificate
     * @return
     */
    @Override
    public int add(Certificate certificate) {
        int insert = certificateMapper.insert(certificate);
        return insert;
    }

    /**
     * 更新一个证书
     */
    @Override
    public int update(Certificate certificate) {
        int i = certificateMapper.updateById(certificate);
        return i;
    }

    /**
     * 删除一个证书
     */
    @Override
    public int del(Integer id) {
        int i = certificateMapper.deleteById(id);
        return i;
    }
}
